import sys
import pygame
from pygame.locals import *

def main(image_path):
    pygame.init()
    
    # Load the image
    image = pygame.image.load(image_path)
    image = pygame.transform.scale(image, (800, 600))
    
    # Set up the window
    screen = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("Pick Pixel by Mouse")
    
    # Main loop
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == QUIT:
                running = False
            elif event.type == MOUSEBUTTONDOWN:
                # Get mouse position
                x, y = pygame.mouse.get_pos()
                # Get pixel color
                color = image.get_at((x, y))
                print(f"RGB at ({x}, {y}): {color}")
                
                # Draw a red dot where the user clicked
                pygame.draw.circle(screen, (255, 0, 0), (x, y), 5)
        
        # Draw the image on the screen
        screen.blit(image, (0, 0))
        pygame.display.flip()
    
    pygame.quit()

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python pick_pixel.py <path_to_image>")
    else:
        main(sys.argv[1])
